package cc.yugu.yhdw.common.protocol.msg02;

import cc.yugu.yhdw.common.protocol.MsgCode;
import cc.yugu.yhdw.common.tool.netty.TypeOperator;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

import java.util.ArrayList;
import java.util.List;

public class Msg021000035 extends Msg021 {

    public static void main(String[] args) throws DecoderException {
        String hex = "022a0000000001406f6300000000000003cc000001643b4017fe0000000002740000000a00000005302d312d310000001e30303030303030303030303030303030303030303030303030303030303000000001300000000000000000000000000000000000000000000000000000000005302d322d320000000f38363731383630333831363938353900000004323133300000005700000025000000260a000000000000154c0000000000000005302d332d330000000f38363731383630333831393731323400000004323337330000006300000026000000270a000000000000153f0000000000000005302d342d340000000f38363731383630333831393731363500000004323031300000005700000023000000241600000000000013590000000000000005302d352d350000000f38363731383630333831363934383700000004323239370000006300000028000000250a00000000000015450000000000000005302d362d360000000f38363731383630333831353438333600000004313838360000004f00000021000000201400000000000013730000050100000005302d372d370000000f38363731383630333831363939363600000004313930300000004d00000024000000241600000000000012c90000000000000005302d382d380000000f38363731383630333831393836343300000004313630390000004600000024000000241400000000000013000000037200000005302d392d390000000f3836373138363033383139383639320000000432303133000000540000001e000000201600000000000013470000000000000007302d31302d31300000000f3836373138363033383230363235350000000431393537000000540000001b0000001d16000000000000131200000000";
        ByteBuf buf = Unpooled.buffer(1024);
        buf.writeBytes(Hex.decodeHex(hex.toCharArray()));

        Msg021000035 msg = new Msg021000035();
        msg.decode(buf);
        System.out.println(msg);
    }

    public List<Box> boxList = new ArrayList<Box>();


    @Override
    public int getMsgCode() {
        return MsgCode.MSG_021000035.getCode();
    }

    @Override
    public void readData(ByteBuf buffer) {
        int size = buffer.readInt();
        for (int i = 0; i < size; i++) {
            Box box = new Box();
            box.read(buffer);
            boxList.add(box);
        }
    }

    public class Box extends TypeOperator {
        public String boxNum;
        public String no;
        public String volume;
        public int socVolume;
        public int temp1;
        public int temp2;
        public byte chargeState;
        public String protectState;
        public int voltage;
        public int electricity;

        public void read(ByteBuf buffer) {
            boxNum = readString(buffer);
            no = readString(buffer);
            volume = readString(buffer);
            socVolume = buffer.readInt();
            temp1 = buffer.readInt();
            temp2 = buffer.readInt();
            chargeState = buffer.readByte();
            char[] str = new StringBuilder(String.format("%0" + 6 + "d", Long.parseLong(Integer.toBinaryString(Integer.parseInt(chargeState+"", 16))))).reverse().toString().toCharArray();
            chargeState = Byte.decode(str[5]+"");
            protectState = readString(buffer);;
            voltage = buffer.readInt();
            electricity = buffer.readInt();
        }
    }
}
